﻿<UserControl x:Class="Bugger.Proxy.TFS.Presentation.Views.TFSSettingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:c="clr-namespace:Bugger.Proxy.TFS.Presentation.Converters"
             xmlns:ts="clr-namespace:Bugger.Proxy.TFS.Presentation.TemplateSelectors"
             xmlns:p="clr-namespace:Bugger.Proxy.TFS.Presentation.Properties"
             xmlns:vm="clr-namespace:Bugger.Proxy.TFS.ViewModels;assembly=Bugger.Proxy.TFS"
             xmlns:dd="clr-namespace:Bugger.Proxy.TFS.Presentation.DesignData"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance dd:SampleTFSSettingViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="550" d:DesignWidth="450">
    <UserControl.Resources>
        <DataTemplate x:Key="TFSFieldComboExpanded">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="A"/>
                    <ColumnDefinition SharedSizeGroup="B"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,10,0" VerticalAlignment="Center"/>
                <TextBlock Text="{Binding AllowedValues, Converter={x:Static c:ItemsToStringConverter.Default}}" Grid.Column="1" VerticalAlignment="Center"/>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="TFSFieldComboCollapsed">
            <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
        </DataTemplate>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="170" />
            <RowDefinition Height="310" />
        </Grid.RowDefinitions>
        <GroupBox Grid.Row="0" Header="{x:Static p:Resources.ConnectSettingsTitle}"
                  IsEnabled="{Binding ProgressType, Converter={x:Static c:ProgressTypesToConnectionEnableConverter.Default}}">
            <Grid Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="5" />
                </Grid.RowDefinitions>
                <Label Content="{x:Static p:Resources.NameOrURIofTFS}" Grid.Row="0" Grid.ColumnSpan="4"
                       VerticalAlignment="Center" HorizontalAlignment="Left" Target="{Binding ElementName=tfsName}" />
                <TextBox x:Name="tfsName" Text="{Binding ConnectUri, Mode=OneWay}"
                         Margin="0,0,25,0" Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="3" IsReadOnly="True" />
                <Button Content="{x:Static p:Resources.GenerateUri}" Command="{Binding UriHelpCommand, Mode=OneWay}" Grid.Column="3"
                        Margin="-10,0,0,0" Grid.Row="1" VerticalAlignment="Center" Height="25" />
                <Label Content="{x:Static p:Resources.UserName}" Margin="0,0,15,0" Grid.Row="2"
                       VerticalAlignment="Center" Grid.ColumnSpan="2" Target="{Binding ElementName=userName}" />
                <Label Content="{x:Static p:Resources.Password}" Grid.Column="2" Margin="15,0,0,0" Grid.Row="2"
                       VerticalAlignment="Center" Grid.ColumnSpan="2" Target="{Binding ElementName=password}" />
                <TextBox x:Name="userName" Text="{Binding UserName, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" Grid.ColumnSpan="2" Margin="0,0,15,0"
                         Grid.Row="3" VerticalAlignment="Center" />
                <PasswordBox x:Name="password" LostFocus="PasswordChanged" Grid.ColumnSpan="2" Grid.Column="2"
                             Margin="15,0,0,0" Grid.Row="3" VerticalAlignment="Center" />
                <Button Content="{x:Static p:Resources.TestConnection}" Command="{Binding TestConnectionCommand, Mode=OneWay}" Grid.Column="3" Margin="-10,0,0,0" Grid.Row="4"
                        VerticalAlignment="Bottom" Height="25" />
                <TextBlock Grid.Row="4" Grid.ColumnSpan="3" Text="{Binding ProgressType, Converter={x:Static c:ProgressTypesToMessageConverter.Default}}" Margin="0,0,50,0" 
                           Visibility="{Binding ProgressType, Converter={x:Static c:ProgressTypesToVisibilityConverter.Default}}" VerticalAlignment="Bottom"/>
                <ProgressBar Grid.Row="5" Grid.ColumnSpan="4" Value="{Binding ProgressValue}" Foreground="{Binding ProgressType, Converter={x:Static c:ProgressTypesToColorConverter.Default}}"
                             Background="{x:Null}" BorderBrush="{x:Null}" IsIndeterminate="{Binding ProgressType, Converter={x:Static c:ProgressTypesToIndeterminateConverter.Default}}"
                             Visibility="{Binding ProgressType, Converter={x:Static c:ProgressTypesToVisibilityConverter.Default}}"/>
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="1" Margin="0,10,0,0" Header="{x:Static p:Resources.MappingSettingsTitle}"
                  IsEnabled="{Binding ProgressType, Converter={x:Static c:ProgressTypesToMappingEnableConverter.Default}}">
            <Grid Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="25"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>
                <TextBlock Text="{x:Static p:Resources.MapTitle}" VerticalAlignment="Center" Grid.ColumnSpan="4"/>
                <ListView ItemsSource="{Binding PropertyMappingCollection}" Grid.Row="1" Grid.ColumnSpan="4" Margin="0,0,0,10">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="170" Header="{x:Static p:Resources.BugProperty}" DisplayMemberBinding="{Binding Key}"/>
                            <GridViewColumn Width="210" Header="{x:Static p:Resources.TFSField}">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox Width="195" Grid.IsSharedSizeScope="True" SelectedValue="{Binding Value}" ItemsSource="{Binding Path=DataContext.TFSFields, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" SelectedValuePath="Name">
                                            <ComboBox.ItemTemplateSelector>
                                                <ts:TFSFieldComboTemplateSelector/>
                                            </ComboBox.ItemTemplateSelector>
                                        </ComboBox>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
                <Label Content="{x:Static p:Resources.BugFilter}" Grid.Row="2" VerticalAlignment="Center"/>
                <ComboBox x:Name="bugFilter" Grid.Row="2" Grid.IsSharedSizeScope="True" Grid.Column="1" VerticalAlignment="Center" ItemsSource="{Binding BugFilterFields}" SelectedValue="{Binding BugFilterField}" SelectedValuePath="Name">
                    <ComboBox.ItemTemplateSelector>
                        <ts:TFSFieldComboTemplateSelector/>
                    </ComboBox.ItemTemplateSelector>
                </ComboBox>
                <TextBlock Text="{x:Static p:Resources.Equal}" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <ComboBox Grid.Row="2" Grid.Column="3" VerticalAlignment="Center" ItemsSource="{Binding SelectedItem.AllowedValues, ElementName=bugFilter}" SelectedItem="{Binding BugFilterValue}"/>
                <Label Content="{x:Static p:Resources.PriorityRed}" Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center" Target="{Binding ElementName=priorityRed}"/>
                <ComboBox x:Name="priorityRed" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Center" Text="{Binding PriorityRed, Mode=OneWay}" ItemsSource="{Binding PriorityValues}" IsReadOnly="True" IsEditable="True" Margin="0,4">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox IsChecked="{Binding IsChecked}" Margin="5"/>
                                <TextBlock Text="{Binding Name}" Margin="5,0,10,0" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Text="{x:Static p:Resources.SplitBy}" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Top"/>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
